<%@ page contentType="text/xml;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="com.hz.supermanage.dao.*,com.hz.supermanage.bean.*" %>
<%
request.setCharacterEncoding("UTF-8");
    boolean bOrgAdmin = true;//SecurityMgr.isOrgAdmin(oaUser);
    String key = request.getParameter("key");
    System.out.println(key);
    //if (key.indexOf("@") != -1) {
    //     request.getRequestDispatcher("unit_role_xml.jsp").forward(request, response);
    //     return;
    //}
    ProgramaDao dao= new ProgramaDao();
%>
<?xml version="1.0" encoding="UTF-8"?>
<tree>
    <%
try {
            if ("0".equals(key)) { //读取根节点
    %>
    <node key="ROOT" name="系统栏目权限" hasChild="<%=dao.isHasRoot()%>" url="R" urls="ALL" icon="/parts/images/img/flagxp.gif">
        <%
            //只有是根机构管理员才显示全部的机构
            Collection emList = null;
            if (bOrgAdmin) {
                emList = new ArrayList();
                emList = dao.getProNode("-1");
            }else {
                emList = new ArrayList();
                 //根据用户所属部门查询
                //emList.add(getOrgNode(oaUser.getOrganization().getPrimaryKey()));
            }
            for (Iterator iterator = emList.iterator(); iterator.hasNext();) {
            	HzsysPrograma pro = (HzsysPrograma) iterator.next();
                boolean hasChild = dao.isHasChild(pro.getProid().toString());

        %>

        <node key="<%=pro.getProid()%>" name="<%=pro.getProname()%>"
              hasChild="<%=hasChild%>"
              url="<%=pro.getProtype()%>" urls="<%=pro.getUrl()%>"
              icon="<%=dao.getNodeIcon(pro.getProtype())%>">
            <%
                if (hasChild) {
                    Collection childs = dao.getChildNodes(pro.getProid().toString());
                    for (Iterator iterator1 = childs.iterator(); iterator1.hasNext();) {
                    	HzsysPrograma pro1 = (HzsysPrograma) iterator1.next();
                        boolean hasChild1 = dao.isHasChild(pro1.getProid().toString());
            %>
            <node key="<%=pro1.getProid()%>" name="<%=pro1.getProname()%>"
                  hasChild="<%=hasChild1%>"
                  url="<%=pro1.getProtype()%>" urls="<%=pro1.getUrl()%>"
                  icon="<%=dao.getNodeIcon(pro1.getProtype())%>"/>
            <%
                    }
                }
            %>
        </node>
        <%
            }  //end for
        %>

    </node>

    <%--<node key="Role@Tree" name="权限模块" hasChild="true" url="Role" icon="/parts/images/img/role.gif"/>
    --%><%
    } else { //非根节点请求

        Collection emList = dao.getChildNodes(key);
        for (java.util.Iterator iterator = emList.iterator(); iterator.hasNext();) {
        	HzsysPrograma map = (HzsysPrograma) iterator.next();

    %>
    <node key="<%=map.getProid()%>" name="<%=map.getProname()%>"
          hasChild="<%=dao.isHasChild(map.getProid().toString())%>"
          url="<%=map.getProtype()%>" urls="<%=map.getUrl()%>"
          icon="<%=dao.getNodeIcon(map.getProtype())%>"/>
    <%
        } //end for

     }
} catch(Exception e){
	e.printStackTrace();
}
    %>
</tree>